package com.itheima.health.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Transactional
@Service
public class UserServiceImpl  extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public UserVO findUserDetailsByUsername(String username) {
        //   涉及 表   t_user_role   t_role    t_role_permisssion   t_permission
        //   1. sql  根据账号 查询用户信息
        UserVO  userVO  = baseMapper.findUserByUsername(username);
        //   2、 用户id  ---- 对应角色 ---keyword
         List<RoleVO> roleVOList =  baseMapper.findRolesByUid(userVO.getId());
        //    3.   角色 id  -----对其权限     keyword----Collection
        for (RoleVO roleVO : roleVOList) {
              List<Permission> permissionList =  baseMapper.findPermissionByRoleId(roleVO.getId());
              roleVO.setPermissionSet(permissionList);
        }
        userVO.setRoles(roleVOList);
        return userVO;
    }
}
